package socrates.ws;

import org.json.JSONArray;
import org.json.JSONObject;

import socrates.dto.AlumnoDTO;
import socrates.ws.RestClient.RequestMethod;

public class WSLogin {
	RestClient con;
	
	public WSLogin(String url, String username , String password){
		url += "?Usuario="+username+"&Contrasena="+password;
		con = new RestClient(url);
	}
	
	public AlumnoDTO login(){
		String response = "";
		AlumnoDTO objAlumno = new AlumnoDTO();
		try {
			con.Execute(RequestMethod.GET);
			response = con.getResponse();
			
			//JSONArray jarray = new JSONArray(response);
			JSONObject jobj = new JSONObject(response);
			//for(int i=0;i<jarray.length();i++){
				//JSONObject jobj = jarray.getJSONObject(i);
				objAlumno.setApellido_Alumno(jobj.getString("Apellidos"));
				objAlumno.setCod_Alumno(Integer.parseInt(jobj.getString("CodAlumno")));
				objAlumno.setContrasena(jobj.getString("Contrasena"));
				objAlumno.setEstado(jobj.getString("Estado"));
				objAlumno.setNombre_Alumno(jobj.getString("Nombres"));
				objAlumno.setUsuario_Alumno(jobj.getString("Usuario"));
				
			//}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			objAlumno = null;
			e.printStackTrace();
		}
		
	 	return objAlumno;
	 	
	}
	
}
